home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / crit.arc / CRIT.DOC < prev    next >
Text File  |  1986-12-01  |  4KB  |  132 lines

  1.           CRIT (2)           Critical Error Handler           CRIT (2)
  2.  
  3.  
  4.      CRITICAL  
  5.  
  6.           critical error handler routines for Microsoft C (et al) 
  7.  
  8.      SYNOPSIS  
  9.  
  10.                int setup_crit();
  11.  
  12.                void restore_crit();
  13.  
  14.  
  15.      DESCRIPTION  
  16.  
  17.           These  two  functions  implement  a  simple  critical  error
  18.           handler for Microsoft C. The setup_crit function works  much
  19.           like  the  standard  library's  setjmp function - when it is
  20.           called initially,  it  returns  0.  When  a  critical  error
  21.           occurs,  control is passed to the point where setup_crit was
  22.           called, and the function appears to return -1.  
  23.  
  24.           If a critical error  occurs,  the  default  DOS  handler  is
  25.           called,  which  will  display  the  'ABORT,  RETRY,  IGNORE'
  26.           message and wait for a key to be struck.  If retry or ignore 
  27.           are selected, then DOS does whatever it is it supposed to do 
  28.           in that situation.  If, however,  the  user  selects  abort,
  29.           then  control is returned to your program at the point where
  30.           the call to setup_crit was made.  
  31.  
  32.           The whole rationale for these functions is for your  program
  33.           to  be  able  to  catch  fatal  errors  and  deal  with them
  34.           relatively gracefully.   Unless  they  are  used,  DOS  will
  35.           unceremoniously   abort   your  program,  leaving  you  with
  36.           dangling files and interrupt vectors.  
  37.  
  38.           The restore_crit function restores the default DOS  critical
  39.           error handler.    It  is  not necessary to call restore_crit
  40.           when your program terminates, as DOS restores  the  critical
  41.           error vector  out  of  your program segment prefix.  It will
  42.           allow you to turn off catching of critical errors.  
  43.  
  44.      CAVEATS  
  45.  
  46.           You  may  call   setup_crit   repeatedly   without   calling
  47.           restore_crit  -  an  interlock is used so that garbage isn't
  48.           put into the critical error interrupt vector.  However, each 
  49.           call to setup_crit overwrites the context saved by  previous
  50.           calls, so they do not nest.  
  51.  
  52.      EXAMPLES  
  53.  
  54.           The  following  example  calls  setup_crit to catch critical
  55.           errors.  It then tries to open a file on drive A:. If you've 
  56.           left the drive door open or have an unformatted diskette  in
  57.           A:,  the  critical  error  will  cause a return to the point
  58.           where setup_crit is called.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.                                       -1-
  65.  
  66.  
  67.           CRIT (2)           Critical Error Handler           CRIT (2)
  68.  
  69.  
  70.           #include <stdio.h>
  71.           main(argc,argv)
  72.           int argc;
  73.           char **argv;
  74.           {
  75.     FILE *foo = NULL;
  76.     static char fnamebuf[65];
  77.     /* attempt to open the file specified by the first command line
  78.     ** argument
  79.     */
  80.     sprintf(fnamebuf,"A:%s",argv[1]);    /* build the file name */
  81.     for (;foo == NULL;)
  82.     {
  83.         if (-1 == setup_crit())    /* set up error handler */
  84.         {
  85.             /* if an error occurs, you will end up here */
  86.             fprintf(stderr,
  87.             "Check to make sure a valid disk is drive A:\n");
  88.             fprintf(stderr,"and that the drive door is closed\n");
  89.             fprintf(stderr,"Hit return to continue\n");
  90.             getchar();
  91.         }
  92.         foo = fopen(fnamebuf,"r");
  93.     }
  94.     restore_crit();    /* turn off critical error handling */
  95.           }
  96.  
  97.      FILES  
  98.  
  99.           testcrit.c, crit.asm 
  100.  
  101.      RETURN VALUE  
  102.  
  103.           setup_crit returns 0 when invoked to set up  critical  error
  104.           catching, and -1 when a critical error occurs.  
  105.  
  106.      SEE ALSO  
  107.  
  108.           setjmp,longjmp 
  109.  
  110.      NOTES  
  111.  
  112.           These functions were written by 
  113.           Kent Williams
  114.           722 Rundell
  115.           Iowa City IA 52240
  116.           (319)338-6053
  117.  
  118.           They  may be used freely, provided proper credit is given to
  119.           their author.  They may be freely distributed,  so  long  as
  120.           all  components  of  this  package  (crit.asm testcrit.c and
  121.           crit.doc) are included, and  no  charge  be  made  beyond  a
  122.           nominal fee for duplication.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.                                       -2-
  131.  
  132.